// pages/coupon/coupon.js
var api = require("../../api.js"),
    app = getApp();
var handler = require("../../utils/function.js");
Page({
    /**
     * 页面的初始数据
     */
    data: {
        img: handler.userImg,
        coupon: wx.getStorageSync("coupon"),
        list: [],
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        var that = this;
        wx.showLoading({})
        app.request({
            url: api.coupon_list.coupon_list,
            method: 'post',
            data: {},
            success: function(rs) {
              wx.hideLoading()
                console.log('优惠卷', rs.data.data)
                that.setData({
                    list: rs.data.data,
                })
            }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        var that = this;
        wx.showNavigationBarLoading();
        app.request({
            url: api.coupon_list.coupon_list,
            method: 'post',
            data: {},
            success: function(rs) {
                console.log('优惠卷', rs.data.data)
                that.setData({
                    list: rs.data.data,
                });
                wx.hideNavigationBarLoading();
            }
        })
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        var that = this;
        wx.showNavigationBarLoading();
        var p = 1;
        p = p + 1;
        app.request({
            url: api.coupon_list.coupon_list,
            method: 'post',
            data: {
                page: p,
            },
            success: function(rs) {
                console.log('优惠卷', rs.data.data)
                that.setData({
                    list: rs.data.data,
                });
                wx.hideNavigationBarLoading();
            }
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {}
})